package lab02.test06;

/**
 * Created by 123 on 2017/10/15.
 */
public class Triangle {
    //1属性
    double length1;
    double length2;
    double length3;
    double perimeter;
    double area;
    boolean a;//判断三边能否围成一个三角形


    //2；行为
    public void judge() {
        if (this.length1 < (this.length3 + this.length2) && this.length2 < (this.length1 + this.length3) && this.length3 < (this.length1 + this.length2)) {
            this.a = true;
            System.out.println("可以围成一个三角形");
        } else {
            this.a = false;
            System.out.println("不能围成一个三角形");
        }
    }

    public void getLength(double length1, double length2, double length3) {
        this.length1 = length1;
        this.length2 = length2;
        this.length3 = length3;//对三角形三边初始化
    }

    public double getArea() {
        double p = (this.length1 = this.length2 + this.length3) / 2;
        double area = Math.sqrt(p * (p - this.length1) * (p - this.length2) * (p - this.length3));
        return area;//计算三角形面积
    }

    public double getPerimeter() {
        double perimeter = this.length1 + this.length2 + this.length3;
        return perimeter;//计算并返回三角形周长
    }
}
